home *** CD-ROM | disk | FTP | other *** search
/ MacFormat España 13 / MacFormat n. 13 (Spain) / Macformat 13.bin / Shareware Internet / Educación / xComputer 1.2 / Examples / Example 2 - The "@" Directive < prev    next >
Encoding:
Text File  |  1995-12-28  |  2.4 KB  |  62 lines

  1. ; Example 2: Assembler Features
  2.  
  3. ; This will multiply two numbers in locations "N1" and "N2" and
  4. ; will put the answer in location "ANS".  (For it to work, the
  5. ; answer must be in the legal range of values.  Or, if you like,
  6. ; it will give a correct answer MOD 2^16.)
  7.  
  8. ; This program illustrates the use of the "@" directive
  9. ; in a program.  This directive tells the computer where
  10. ; in memory to load the items that follow.  Imagine that,
  11. ; for some reason, I would like my multiplication program
  12. ; to start at location 30 and the data for the program
  13. ; for the program to be at location 20.  I can use the
  14. ; @ directive to accomplish this.
  15.  
  16.  
  17. @20  ; This says that when the program is loaded, the
  18.      ;   following item is to be at location 20.  Thus,
  19.      ;   N1 will be 20, N2 will be 21, and ANS will be 22.
  20.  
  21. N1:   13    ; The number 13 is stored in a location named "N1".
  22. N2:   56    ; 56 is in a location named "N2".  These are the
  23.             ;    numbers that will be multiplied; change them
  24.             ;    to any values you like.
  25. ANS:  data  ; "ANS" is the name for a memory location that
  26.             ;    will hold the product of N1 and N2 when
  27.             ;    the program ends.
  28.  
  29.  
  30. @PC mult    ; "@PC" is a special form of the @ directive that
  31.             ;    tells the computer to load the following
  32.             ;    number into the PC register as it assembles
  33.             ;    and loads this program.  In this case, the
  34.             ;    value to be loaded into the PC is given by
  35.             ;    a label, "mult".  The point of this is that
  36.             ;    the computer will begin execution at the
  37.             ;    location in the PC, so I want PC to be
  38.             ;    the first instruction in the program.  (The
  39.             ;    value of the PC could also be set by
  40.             ;    hand, using the "Load PC" button.)
  41.  
  42. @30         ; The following items -- the program itself -- will
  43.             ;   be loaded starting at location 30.  (So, in fact,
  44.             ;   "mult" refers to location 30.)
  45.  
  46. mult:  lod-c 0     ; A program for multiplying two numbers.
  47.        sto ANS     ;   (For the meaning of individual instructions,
  48. loop:  lod N1      ;   look at the end of the file "READ ME
  49.        jmz done    ;   (with instructions!)".)
  50.        shr
  51.        sto N1
  52.        jmf doAdd
  53. shift: lod N2
  54.        shl
  55.        jmz done
  56.        sto N2
  57.        jmp loop
  58. doAdd: lod N2
  59.        add ANS
  60.        sto ANS
  61.        jmp shift
  62. done:  hlt